<template>
  <div class="company">
    <div>
      <el-button size="mini" @click="queryCompany">{{ $t('btn.reload') }}</el-button>
      <el-button type="primary" size="mini" @click="save">{{ $t('btn.save') }}</el-button>
    </div>
    <el-form
      :model="panyForm"
      label-width="110px"
    >
      <el-form-item :label="$t('market.companyname')">
        <el-input v-model.trim="panyForm.fcompanyname" size="mini" />
      </el-form-item>
      <el-form-item :label="$t('market.localCurr')">
        <el-select v-model="panyForm.fcurrencyId" size="mini">
          <el-option v-for="item in currencysData" :key="item.fcurrencyId" :label="item.fname" :value="item.fcurrencyId" />
        </el-select>
      </el-form-item>
      <el-form-item :label="$t('market.nextClose')">
        <el-input-number v-model="panyForm.nextCloseYear" size="mini" /> {{ $t('market.year') }}<!--年-->
        <el-input-number v-model="panyForm.nextCloseMonth" size="mini" /> {{ $t('market.month') }}<!--月-->
      </el-form-item>
      <el-form-item :label="$t('market.nextMaintain')">
        <el-input-number v-model="panyForm.nextMaintainYear" size="mini" /> {{ $t('market.year') }}<!--年-->
        <el-input-number v-model="panyForm.nextMaintainMonth" size="mini" /> {{ $t('market.month') }}<!--月-->
      </el-form-item>
      <el-form-item :label="$t('market.nextSettle')">
        <el-input-number v-model="panyForm.nextSettleYear" size="mini" /> {{ $t('market.year') }}<!--年-->
        <el-input-number v-model="panyForm.nextSettleMonth" size="mini" /> {{ $t('market.month') }}<!--月-->
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import { queryCompanyConfig, saveCompanyConfig } from '@/api/basicManagement/company'
import { queryBaseCurrencyList } from '@/api/basicManagement/currencyRates'
export default {
  name: 'Company',
  data() {
    return {
      panyForm: {
        fcompanyname: '',
        nextCloseYear: '',
        nextCloseMonth: '',
        nextSettleYear: '',
        nextSettleMonth: '',
        nextMaintainYear: '',
        nextMaintainMonth: ''

      },
      currencysData: [] // 本位币
    }
  },
  created() {
    // 详情
    this.queryCompany()
    this.queryTBdCurrency()
  },
  methods: {
    // 详情
    queryCompany() {
      queryCompanyConfig({}).then(res => {
        if (res.code === 0) {
          this.panyForm = res.data
        } else {
          this.$confirm(res.message, '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'error'
          })
        }
      })
    },
    // 结算币别
    async queryTBdCurrency() {
      const DATA = {
        pageNum: 1, // 当前页
        pageSize: 100 // 每页显示多少条数据
      }
      if (this.currencysData.length > 0) {
        return
      }
      const { data: RES } = await queryBaseCurrencyList(DATA)
      this.currencysData = RES.list
    },
    // 修改
    save() {
      saveCompanyConfig({ ...this.panyForm }).then(res => {
        if (res.code === 0) {
          this.queryCompany()
          this.$message({
            showClose: true,
            message: res.message,
            type: 'success'
          })
        } else {
          this.$confirm(res.message, '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'error'
          })
        }
      })
    }
  }
}
</script>

<style scoped lang="scss">
.company {
  padding: 10px;
  background: #ffffff;
  min-height: 89vh;
  .el-input::v-deep .el-input__inner {
    height: 30px;
    line-height: 30px;
  }
  .el-form {
    margin-top: 20px;
    .el-form-item {
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      width: 320px;
      margin-bottom: 10px;
    }
    .el-form-item:nth-child(2) {
      margin-bottom: 0;
      width: 100%;
    }
    &::v-deep .el-input-number .el-input{
      width: 100%;
      width: 80px;
    }
    &::v-deep .el-input-number--mini .el-input__inner {
      padding: 0;
    }
    &::v-deep .el-input-number--mini{
      width: 100%;
      width: 80px;
    }
    &::v-deep .el-input-number__increase{
      display: none;
    }
    &::v-deep .el-input-number__decrease{
      display: none;
    }
  }
}
</style>
